<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content">待办事项</block>
		</cu-custom>

		<view class="page-content" :style="{height:this.ContentArea+'px',paddingTop:'30rpx'}">
			<view class="page-content-main">
				<view class="select-box">
					<!-- <view style="position: relative;">
						<uni-datetime-picker v-model="createTime" type="line">
							<view class="select">
								<view class="select-value">{{ createTimeShow }}</view>
								<view class="select-icon" v-if="createTime ==''">
									<image src="@/static/images/downArrow.png" mode="aspectFit" />
								</view>
							</view>
						</uni-datetime-picker>
						<view class="cuIcon-roundclose" v-if="createTime !=''"
							style="z-index: 9;width: 20px;height: 20px;position: absolute;right: 55rpx;top: 23rpx;color: #FFFFFF;"
							@click="clearDatetimePicker">
						</view>
					</view> -->
					<view class="mySelect">
						<!-- <my-select range-key="text" value-key="value" dict-code="approval_status" class="mySelect-value"
							style="position: inherit;" v-model="approvalStatus" /> -->
						<view style="margin-top: 19rpx;margin-right: 50rpx;margin-left: 10rpx;">
							<picker @change="PickerChangeSeven" :value="indexSeven" :range="pickerSeven"
								:data-array="pickerSeven" range-key="label">
								<view style="color: #FFFFFF;width: 100%;margin-left: 10px;">
									{{indexSeven > -1 && pickerSeven.length > 0 ? pickerSeven[indexSeven].label : '请选择'}}
								</view>
							</picker>
						</view>

						<view class="mySelect-icon">
							<image src="@/static/images/downArrow.png" mode="aspectFit" />
						</view>
					</view>
				</view>
				<view v-for="(item,index) in dataList" @click.stop="goDetail(item)"
					style=" position: relative; height: 188rpx; background-color: #F9F9F9;  border-radius: 15px;display: flex; margin-top: 24rpx;">
					<view style="margin-top: 20rpx; margin-left: 20rpx;" >
						<image :src="item.avatar" style="height: 82rpx; width: 82rpx;" />
					</view>
					<view style="margin: 18rpx 0 0 32rpx ;">
						<view>
							<text style="font-size: 20rpx; font-weight: bold; ">
								{{item.createTime}}
							</text>
						</view>
						<view style="height:28rpx; margin-top: 20rpx;">
							<text style="font-size: 28rpx; font-weight: bold; ">
								{{item.title}}
							</text>
						</view>
						<!-- <view v-if="item.state=='1'"
							style="border-radius: 10rpx 10rpx 10rpx 10rpx;width: 150rpx; background-color: rgba(255, 173, 4, 0.22);  padding:8rpx 14rpx 8rpx 18rpx; margin-top: 23rpx;">
							<text style="color:rgba(255, 173, 4, 1); font-size: 20rpx;">
								已催办3次
							</text>
						</view>
						<view v-if="item.state=='2'"
							style="border-radius: 10rpx 10rpx 10rpx 10rpx;width: 150rpx; background-color: rgba(52, 167, 89, 0.17);  padding:8rpx 14rpx 8rpx 18rpx; margin-top: 23rpx;">
							<text style="color:rgba(52, 167, 89, 1); font-size: 20rpx;">
								等待审批
							</text>
						</view> -->
						<view v-if="item.status_dictText == '同意'"
							style="border-radius: 10rpx 10rpx 10rpx 10rpx;width: 80rpx; background-color: rgba(52, 167, 89, 0.17);  padding:8rpx 14rpx 8rpx 18rpx; margin-top: 23rpx;">
							<text style="color:rgba(52, 167, 89, 1); font-size: 20rpx;">
								{{item.status_dictText}}
							</text>
						</view>
						<view v-if="item.status_dictText == '驳回'"
							style="border-radius: 10rpx 10rpx 10rpx 10rpx;width: 80rpx; background-color: rgba(255, 0, 0, 0.17);  padding:8rpx 14rpx 8rpx 18rpx; margin-top: 23rpx;">
							<text style="color:red; font-size: 20rpx;">
								{{item.status_dictText}}
							</text>
						</view>
						<view v-if="item.status_dictText == '待审'"
							style="border-radius: 10rpx 10rpx 10rpx 10rpx;width: 80rpx; background-color: rgba(255, 173, 4, 0.22);  padding:8rpx 14rpx 8rpx 18rpx; margin-top: 23rpx;">
							<text style="color:rgba(255, 173, 4, 1); font-size: 20rpx;">
								{{item.status_dictText}}
							</text>
						</view>
					</view>
					<view style="position: absolute;right: 35rpx;" v-if="item.status_dictText === '待审'">
						<view @click.stop="agree(item)">
							<button
								style="background-color: rgba(69, 145, 254, 1);border-radius: 20rpx;font-size:12px;padding: 2rpx 34rpx ;color: rgba(255, 255, 255, 1);display: inline-block; margin-top: 20rpx; margin-left: 60rpx;">同意</button>
						</view>
						<view  @click.stop="disagree(item)">
							<button
								style="background-color: rgba(167, 52, 52, 1);border-radius: 20rpx;font-size:12px;padding: 2rpx 34rpx ;color: rgba(255, 255, 255, 1);display: inline-block; margin-top: 10rpx; margin-left: 60rpx;">驳回</button>
						</view>
					</view>
				</view>
			</view>

		</view>
		<uni-popup ref="agreePopup" background-color="#fff" :mask-click="false">
			<view
				style="text-align: center;background-color: #FFFFFF;padding: 11rpx;width: 580rpx;height: 470rpx;border-radius: 42rpx;">
				<view class="submit-item">
					<image class="submit-icon" src="@/static/images/editUserIcon.png" />
				</view>
				<view style="margin-top: 28rpx;">
					<text class="submit-text">确定要同意该申请吗</text>
				</view>
				<br>
				<view style="display: flex;">
					<button @click="sureAgree" style="border-radius: 20rpx; background-color: rgba(69, 145, 254, 1);
							color: rgba(255, 255, 255, 1);width: 230rpx;margin-top: 50rpx;">确定</button>
					<button @click="cancelAgree" style="border-radius: 20rpx; background-color: gray;
							color: rgba(255, 255, 255, 1);width: 230rpx;margin-top: 50rpx;">取消</button>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="isAgree" background-color="#fff" :mask-click="false">
			<view
				style="text-align: center;background-color: #FFFFFF;padding: 11rpx;width: 580rpx;height: 470rpx;border-radius: 42rpx;">
				<view class="submit-item">
					<image class="submit-icon" src="@/static/zhinengshenheshenchashenhe 1.png" />
				</view>
				<view style="margin-top: 28rpx;">
					<text class="submit-text">你已同意用户的申请</text>
				</view>
				<button @click="agreeCancel" style="border-radius: 20rpx; background-color: rgba(69, 145, 254, 1);
				color: rgba(255, 255, 255, 1);width: 300rpx;margin-top: 27rpx;">确定</button>
			</view>
		</uni-popup>
		<uni-popup ref="isDisagree" background-color="#fff" :mask-click="false">
			<view
				style="background-color: #FFFFFF;padding: 11rpx 30rpx;width: 580rpx;height: 400rpx;border-radius: 42rpx;">
				<view style="margin-top: 28rpx;margin-left: 15rpx;">
					<text class="submit-text">驳回</text>
				</view>
				<view class="cu-form-group"
					style="background-color: rgba(243, 243, 243, 1);border-radius: 15px;margin-top: 40rpx;">
					<input v-model="reason" placeholder="请输入驳回理由" name="input" style="font-size: 25rpx;"></input>
				</view>
				<button style="background-color: rgba(217, 217, 217, 1);
							color: rgba(86, 85, 85, 1); margin-top: 30rpx;padding: 2rpx 85rpx; display: inline-block; "
					@click="rejectCancel">取消</button>
				<button style="background-color: rgba(69, 145, 254, 1);
				color: rgba(255, 255, 255, 1);margin-left:34rpx; display: inline-block;padding: 2rpx 85rpx; "
					@click="rejectSure">确定</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import moment from 'moment';
	import configService from '@/common/service/config.service.js'
	export default {
		data() {
			return {
				ContentArea:0,
				index: 0,
				array: ['全部', '已完成', '未完成'],
				createTime: moment().format('YYYY-MM-DD'),
				reason: '',
				approvalStatus: '3',
				dataList: [],
				refreshing: true,
				pageSize: 9999,
				pageNo: 1,
				total: 0,
				listUrl: '',
				examineId: '',
				indexSeven: 0,
				pickerSeven: [{
					key: 3,
					label: '待审',
				}, {
					key: 4,
					label: '驳回',
				}, {
					key: 5,
					label: '同意',
				}],
			}
		},
		mounted() {
			this.getList()
		},
		watch: {
			createTime: {
				immediate: true,
				handler(val, old) {
					this.getList()
				},
			},
			approvalStatus: {
				immediate: true,
				handler(val, old) {
					this.getList()
				},
			},
		},
		computed: {
			createTimeShow: function() {
				return moment(this.createTime).isValid() ? moment(this.createTime).format('MM-DD') : '请选择'
			}
		},
		methods: {
			goDetail(item){
				console.log('item',item)
				// if(item.status == 3) {
				// 	// 只有待审状态可跳转
					if(item.approvalType == 0) {
						//待入职申请
						uni.navigateTo({
							url: '/pages/oa/crm_employment_pending/pendingDetails/index?id=' + item.applicationId + '&status=' + item.status + '&examineId=' + item.id
						})
					} else if(item.approvalType == 1) {
						// 入职申请
						uni.navigateTo({
							url: '/pages/oa/crm_employment_list/employmentDetails/index?id=' + item.applicationId + '&status=' + item.status+ '&examineId=' + item.id
						})
					} else if(item.approvalType == 2) {
						// 调岗申请
						uni.navigateTo({
							url: '/pages/oa/crm_job_transfer_list/jobTransferDetails/index?id=' + item.applicationId + '&status=' + item.status+ '&examineId=' + item.id
						})
					} else if(item.approvalType == 3) {
						// 调薪申请
					}else if(item.approvalType == 4) {
						// 离职申请 
						uni.navigateTo({
							url: '/pages/resignationApplication/resignationApplicationDetails/index?id=' + item.applicationId + '&status=' + item.status+ '&examineId=' + item.id
						})
					} else if(item.approvalType == 5){
						// 转正申请 
						uni.navigateTo({
							url: '/pages/confirmationApplication/confirmationApplicationDetails/index?id=' + item.applicationId + '&status=' + item.status+ '&examineId=' + item.id
						})
					} else if(item.approvalType == 6){
						// 再次组织邀请申请
					} else if(item.approvalType == 7){
						// 用人需求申请
					} else if(item.approvalType == 8){
						// 手机号变更
					} else if(item.approvalType == 9){
						// 合同填写
					} else if(item.approvalType == 10){
						// 住宿申请 /pages/stayApplication/stayApplicationDetail/index
						uni.navigateTo({
							url: '/pages/stayApplication/stayApplicationDetail/index?id=' + item.applicationId + '&status=' + item.status+ '&examineId=' + item.id
						})
					} else if(item.approvalType == 11){
						// 换宿申请
						uni.navigateTo({
							url: '/pages/changeDorm/changeDormDetail/index?id=' + item.applicationId + '&status=' + item.status+ '&examineId=' + item.id
						})
						
					} else if(item.approvalType == 12){
						// 考勤记录
						
					} else if(item.approvalType == 13){
						// 退宿申请 
						uni.navigateTo({
							url: '/pages/retreatApplication/retreatApplicationDetails/index?id=' + item.applicationId + '&status=' + item.status+ '&examineId=' + item.id
						})
						
					} else if(item.approvalType == 14){
						// 入职申请-黑名单
						
					} else if(item.approvalType == 15){
						// 定岗定编申请 
						
					} 
				// }
			},
			getFileAccessHttpUrl(avatar, subStr) {
				if (!subStr) subStr = 'http'
				if (avatar && avatar.startsWith(subStr)) {
					return avatar;
				} else {
					return configService.staticDomainURL + "/" + avatar;
				}
			},
			PickerChangeSeven(e) {
				this.indexSeven = e.detail.value
				this.approvalStatus = this.pickerSeven[e.detail.value].key
			},
			getList() {
				let params = {}
				if (this.createTime) {
					params = {
						pageNo: this.pageNo,
						pageSize: this.pageSize,
						createTime: this.createTime + " 00:00:00",
						status: this.approvalStatus
					}
				} else {
					params = {
						pageNo: this.pageNo,
						pageSize: this.pageSize,
						status: this.approvalStatus
					}
				}
				this.$http.get("/crm_on_hand/crmOnHand/list", {
					params: params
				}).then(res => {
					if (res.data.success) {
						let records = res.data.result.records
						this.dataList = records
						for (var i = 0; i < this.dataList.length; i++) {
							this.dataList[i]['avatar'] = this.getFileAccessHttpUrl(this.dataList[i]['avatar'])
						}
						console.log('this.dataList-事项',this.dataList )
					}
				})
			},
			clearDatetimePicker() {
				this.createTime = ''
			},
			agree(item) {
				console.log('iiiii-id',item.id)
				this.examineId = item.id
				this.$refs.agreePopup.open('center')
			},
			disagree(item) {
				this.examineId = item.id
				this.$refs.isDisagree.open('center')
			},
			agreeCancel() {
				this.$refs.isAgree.close()
				this.getList()
			},
			rejectCancel() {
				this.$refs.isDisagree.close()
			},
			rejectSure() {
				console.log('this.examineId',this.examineId)
				this.$http.post("/crm_on_hand/crmOnHand/rejectTrial", {
					id: this.examineId,
					reason: this.reason
				}).then(res => {
					if (res.data.success) {
						this.$refs.isDisagree.close()
						this.getList()
					}else{
						this.$tip.toast(res.data.message)
						this.$refs.isDisagree.close()
					}
				})
			},
			sureAgree(){
				console.log('this.examineId',this.examineId)
				this.$http.post("/crm_on_hand/crmOnHand/agreeTrial", {
					id: this.examineId
				}).then(res => {
					console.log('同意申请12',res)
					if (res.data.success) {
						this.getList()
						this.$refs.isAgree.open('center')
						this.$refs.agreePopup.close()
					}else{
						this.$tip.toast(res.data.message)
						this.$refs.agreePopup.close()
					}
				})
			},
			cancelAgree(){
				this.$refs.agreePopup.close()
			},
		}
	}
</script>

<style lang="scss" scoped>
	image {
		width: 100%;
		height: 100%;
	}

	.blackList {
		height: 100%;
		overflow: hidden;
	}

	.page-search {
		padding-left: 34rpx;
		margin-bottom: 12rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.search {
		width: 688rpx;
		height: 86rpx;
		background-color: rgba(249, 249, 249, 1);
		border-radius: 60rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 24rpx;
		padding-right: 24rpx;

		.search-left {
			width: 28rpx;
			height: 28rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.search-center {
			margin-left: 22rpx;
		}

		.search-placeholder {
			font-size: 28rpx;
			font-weight: 400;
			color: #7C7C7C;
		}


	}

	.filter-btn {
		width: 40rpx;
		height: 40rpx;
		margin-right: 42rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.page-content-main {
		height: calc(100% - 12rpx - 86rpx);
		border-top-left-radius: 64rpx;
		border-top-right-radius: 64rpx;
		// background-color: #F9F9F9;
		padding: 26rpx 34rpx 0 34rpx
	}

	.select-box {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;

	}

	.select {
		width: 160rpx;
		height: 74rpx;
		border-radius: 60rpx;
		background-color: #4591FE;
		margin-bottom: 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin-right: 48rpx;
		position: relative;

		.select-value {
			font-size: 28rpx;
			font-weight: 400;
			color: #FFFFFF;
			margin-right: 18rpx;
		}

		.select-icon {
			width: 22rpx;
			height: 22rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			position: absolute;
			right: 20rpx;
			top: 25rpx;
		}
	}

	.list {
		height: calc(100% - 74rpx - 20rpx);
	}

	.list-item {
		border-radius: 28rpx;
		background-color: #FFFFFF;
		padding: 26rpx 24rpx 28rpx 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin-bottom: 26rpx;
		position: relative;

		.list-item-leftCenter {
			display: flex;
			flex-direction: row;
		}

		.list-item-left {
			width: 86rpx;
			height: 86rpx;
			margin-right: 26rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.list-item-center {
			.list-item-row {
				display: flex;
				flex-direction: row;
				margin-bottom: 20rpx;

				.list-item-name {
					color: #101317;
					font-size: 32rpx;
					margin-right: 16rpx;
				}

				.list-item-sex {
					padding: 5rpx 20rpx;
					border-top-right-radius: 40rpx;
					border-bottom-right-radius: 40rpx;
					border-bottom-left-radius: 20rpx;
					background-color: rgba(234, 171, 78, 0.35);
					line-height: 42rpx;
					text-align: center;
					color: rgba(255, 173, 4, 1);
					font-size: 24rpx;
				}

				.list-item-row-icon {
					width: 38rpx;
					height: 38rpx;
					margin-right: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.list-item-row-title,
				.list-item-row-value {
					font-size: 24rpx;
					font-weight: 400;
					color: #101317;
					line-height: 38rpx;
				}

			}
		}

		.list-item-btn {
			width: 36rpx;
			height: 36rpx;
			margin-top: 56rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.list-item-tab {
			width: 132rpx;
			height: 56rpx;
			text-align: center;
			line-height: 56rpx;
			background-color: rgba(69, 145, 254, 0.4);
			position: absolute;
			top: 0;
			right: 0;
			border-top-right-radius: 26rpx;
			border-bottom-left-radius: 20rpx;
		}

		.list-item-tab-text {
			font-size: 26rpx;
			color: rgba(69, 145, 254, 1)
		}
	}

	.nav-right-image {
		width: 80rpx;
		height: 80rpx;
		margin-left: 15px;
	}

	.fun-wrap {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(3, 3, 3, 0.28);
		z-index: 10000;
	}

	.fun-box {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
		width: 556rpx;
		height: 444rpx;
		border-top-left-radius: 42rpx;
		border-bottom-left-radius: 42rpx;
		border-bottom-right-radius: 42rpx;
		position: absolute;
		right: 74rpx;
		background-color: #FFFFFF;
		padding-top: 35rpx;
	}

	.fun-item {
		width: 185rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-bottom: 44rpx;
	}

	.fun-icon {
		width: 92rpx;
		height: 92rpx;
		margin-bottom: 22rpx;
	}

	.cu-form-group {
		background-color: transparent;
	}

	::v-deep {
		.cu-form-group uni-picker .picker {
			color: #FFFFFF;
		}

		.cu-form-group uni-picker::after {
			opacity: 0;
		}
	}

	.submit-icon {
		width: 118rpx;
		height: 118rpx;
		margin-top: 58rpx;
	}

	.mySelect {
		position: relative;
		background-color: #4591FE;
		border-radius: 60rpx;
		height: 74rpx;

		.mySelect-value {
			position: inherit;
			margin-left: 10rpx;
			margin-right: -25rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #FFFFFF;
		}

		.mySelect-icon {
			width: 22rpx;
			height: 22rpx;
			position: absolute;
			top: 30%;
			right: 18%;
		}
	}
</style>